﻿using ImGuiNET;
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using TTEditor;
using TTEngine;

namespace FakeUnity.Editor
{
    class WindowOutput : IWindow, ILogger
    {
        public WindowOutput()
        {
            if (logs == null)
            {
                logs = new List<LogItem>();
                unsafe
                {
                    FakeUnity.Warp.FrameworkNative.SetAssertCallBack(onIMGUIAsset);
                }
            }
        }
        class LogItem
        {
            public string info;
            public Vector4 color;
        }
        static List<LogItem> logs = null;
        unsafe static void onIMGUIAsset(char* expr, char* filename, int line)
        {
            logs.Add(new LogItem{info= "UILog:" + new string(expr) + "," + new string(filename) + ":" + line,color=new Vector4(1,1,1,1)});
        }
        public void OnUpdate()
        {

        }
        public void OnGUI()
        {
            ImGui.Text("this is output win.");
            if (ImGui.Button("clear"))
            {
                logs.Clear();
            }
            foreach(var l in logs)
            {
                ImGui.PushStyleColor(ImGuiCol.Text, l.color);
                ImGui.Text(l.info);
                ImGui.PopStyleColor();
            }
        }

        public void OnClose()
        {
        }

        public void Show()
        {
        }

        public void Log(string str)
        {
            logs.Add(new LogItem { info = str, color = new Vector4(1, 1, 1, 1) });
        }

        public void Warning(string str)
        {
            logs.Add(new LogItem { info = str, color = new Vector4(1, 1, 0.5f, 1) }); ;
        }

        public void Error(string str)
        {
            logs.Add(new LogItem { info = str, color = new Vector4(1, 0.5f, 0.5f, 1) }); ;
        }

        public void AddSubLogger(ILogger logger)
        {
        }
    }
}
